package com.zahb.qadx.ui.adapter;


import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zahb.qadx.R;
import com.zahb.qadx.model.CertificateListBean;

import org.jetbrains.annotations.NotNull;


public class CertificateAdapter extends BaseQuickAdapter<CertificateListBean.ListBean, BaseViewHolder> {



    public int type=0;

    public CertificateAdapter(int layoutResId) {
        super(layoutResId);
        addChildClickViewIds(R.id.tvLook);
    }

    @Override
    protected void convert(@NotNull final BaseViewHolder helper, CertificateListBean.ListBean item) {


//        helper.setText(R.id.tvTitle,item.getName())
//                .setText(R.id.tvSource,"证明来源："+item.getSourceName())
//                .setText(R.id.tvType,"证明类型："+(item.getType()==1?"学时证明":"考试通过证明"))
//                .setText(R.id.tvType,"颁发日期："+splitTime(item.getIssueDate()))
//                .setText(R.id.tvDate,"失效日期："+splitTime(item.getInvalidTime()));

        if(type==0){
            if(isValidate(item)){
                helper.setBackgroundResource(R.id.rl, R.drawable.certificate_list_bg);
            }else{
                helper.setBackgroundResource(R.id.rl, R.drawable.certificate_list_bg_two);
            }

            helper.setText(R.id.tvTitle,item.getName())
                    .setText(R.id.tvSource,"证明来源："+item.getSourceName())
                    .setText(R.id.tvType,"证明类型："+(item.getType()==1?"学时证明":"考试通过证明"))
                    .setText(R.id.tvDate,"失效日期："+splittime(item.getInvalidTime()));


        }else{
            if(isValidate(item)){
                helper.setBackgroundResource(R.id.rl, R.drawable.certificate_list_bg_three);
            }else{
                helper.setBackgroundResource(R.id.rl, R.drawable.certificate_list_bg_two);
            }

            helper.setText(R.id.tvTitle,item.getName())
                    .setText(R.id.tvType,"颁发日期："+splittime(item.getIssueDate()))
                    .setText(R.id.tvDate,"失效日期："+splittime(item.getInvalidTime()));
                    helper.getView(R.id.tvSource).setVisibility(View.GONE);
        }

        if(isValidate(item)){
            helper.setImageResource(R.id.ivValidate, R.mipmap.certificate_tag_valite);
        }else{
            helper.setImageResource(R.id.ivValidate, R.mipmap.certificate_tag_invalite);
        }

    }

    public boolean isValidate(CertificateListBean.ListBean item){
        if((item.getValidityType()==1&&item.getState()==1)||item.getValidityType()==0){
            return true;
        }else{
            return false;
        }
    }
    public static String splittime(String time){
        String[] times =  time.split("T");
        return times[0];
    }

}
